<template>
    <div class="dealer">
        <div style="position:fixed;width:calc(100% - 235px);z-index: 999;box-shadow: 0px 0px 10px #ccc;top:90px ">
            <Row class="btns">
                <Col class="channelClick">
                    <!-- 当前按钮是否展示0（新增，修改）表示展示、1表示不展示（查看页面），-->
                    <Button type="primary" @click="save()" v-if="this.typeCode == '0'" :loading="loadingSave" icon="ios-create-outline">保存</Button>
                    <!-- <Button type="primary" @click="blacklist()" v-if="this.typeCode == '1'" icon="ios-create-outline">黑名单申请</Button> -->
                    <Button type="primary" @click="back()" icon="ios-create-outline">返回</Button>
                </Col>
            </Row>
            <ul class="channel_text channel_title">
                <li v-for="(item,index) in tabsType" :key="index" :class="{active:curTab===index}" @click="toggle(index)">
                    <p></p>
                    <span>{{item.value}}</span>
                </li>
            </ul>
        </div>
        <div class="specific_field" style="padding-top: 150px;">
            <div v-show="curTab===0">
                <!--基本信息-->
                <basic-info ref="basicInfoModify" :channelType="channelType" :newCarRole="newCarRole" :oldCarRole="oldCarRole" :channelStatus="channelStatus" :channelStatusOldCar="channelStatusOldCar" ></basic-info>
                <Spin fix v-if="spinShow">
                    <Icon type="ios-loading" size=60 class="demo-spin-icon-load"></Icon>
                    <div>请稍后...</div>
                </Spin>
            </div>
            <div v-show="curTab===1">
                <!--收款账号信息-->
                <account-info ref="accountModify" :isNewCarRole="isNewCarRole" :isOldCarRole="isOldCarRole"></account-info>
            </div>
            <div v-show="curTab===2">
                <!--备案信息-->
                <record-info ref="recordInfo" :channelType="channelType" :channelId="channelId"></record-info>
            </div>
            <div v-show="curTab===3">
                <!--系统用户信息-->
                <use-info ref="useInfo" :channelId="channelId" :operationUser="operationUser" ></use-info>
            </div>
            <div v-if="curTab===4">
                <file-operation  :uploadParam="uploadParam" :isInt="canUpload" :path="path" :readOnly="uploadReadOnly" ></file-operation>
            </div>
            <div v-show="curTab===5">
                <!--档案日志-->
                <archives-log ref="archivesLog"></archives-log>
            </div>
        </div>

    </div>
</template>
<script>
    import "_p/afs-channel/assets/css/channelBase.css";
    import BasicInfo from "./basic-info/basicInfoModify.vue";
    import AccountInfo from "./payment-account/accountModify.vue";
    import RecordInfo from "./record-info/recordInfo.vue";
    import UseInfo from "./use-info/useInfo.vue";
    import ArchivesLog from "./archives-log/archivesLog.vue";
    import FileOperation from "_p/basic/pages/image/upload-file/fileOperation.vue";

    export default {
        name:"dealerMain",
        props: {

        },
        data(){
            return{
                operationUser:"",
                //默认隐藏父页面
                channelManage:true,
                channelId:"",
                /*默认从基本信息开始*/
                typeCode:0,
                curTab:0,
                operationType:0,
                //渠道归属
                channelType:"",
                //是否拥有新车权限
                isNewCarRole:"",
                //是否拥有二手车权限
                isOldCarRole:"",
                newCarRole:"",
                oldCarRole:"",
                loadingStaging:false,
                loadingSave:false,
                spinShow: false,
                channelStatus:"",
                channelStatusOldCar:"",
                isShowFile:false,
                canUpload:false,
                path:"channel",
                uploadReadOnly:false,
                businessType:[],
                uploadParam: {
                    busiNo: "",
                    belongNo: "",
                    busiType: "",
                    busiData: {}
                },
                tabsType:[
                    {
                        value:"基本信息"
                    },
                    {
                        value:"收款账号信息"
                    },
                    {
                        value:"备案信息"
                    },
                    {
                        value:"系统用户信息"
                    },
                    {
                        value:"附件"
                    },
                    {
                        value:"档案日志"
                    }
                ],
                remarkForm:{
                    remark:"",
                },
                remarkFormValidate:{
                    remark:[
                    ]
                },
            }
        },
        components:{
            //注入子组件
            BasicInfo,
            AccountInfo,
            RecordInfo,
            UseInfo,
            ArchivesLog,
            FileOperation
        },
        created(){
        },
        methods:{
            init() {
                if(this.afs.getPageParams(this).operationType==0){
                    //新增操作
                    //设置页面是否禁用
                    //传入页面渠道类型判断渠道归属赋值
                    this.channelType=this.afs.getPageParams(this).channelType;
                    //传入是否拥有新车账号权限
                    this.isNewCarRole=this.afs.getPageParams(this).isNewCarRole;
                    //传入是否有二手车账户权限
                    this.isOldCarRole=this.afs.getPageParams(this).isOldCarRole;
                    this.newCarRole=this.afs.getPageParams(this).isNewCarRole;
                    this.oldCarRole=this.afs.getPageParams(this).isOldCarRole;
                    this.basicInfoView(this.afs.getPageParams(this).infoView);
                }else if(this.afs.getPageParams(this).operationType==1){
                    
                    //传入是否拥有新车账号权限
                    this.isNewCarRole=this.afs.getPageParams(this).isNewCarRole;
                    //传入是否有二手车账户权限
                    this.isOldCarRole=this.afs.getPageParams(this).isOldCarRole;
                    this.newCarRole=this.afs.getPageParams(this).isNewCarRole;
                    this.oldCarRole=this.afs.getPageParams(this).isOldCarRole;
                    //传入页面渠道类型判断渠道归属赋值
                    this.channelType=this.afs.getPageParams(this).channelType;
                    console.log("我是什么类型--------------------------"+this.channelType)
                    if(this.channelType=='01'){
                        // 说明是直营
                        this.operationUser='01';
                    }else{
                        // 说明我是非直营
                        this.operationUser='00';
                    }
                    //获取渠道基本信息
                    this.channel(this.afs.getPageParams(this).channelId);
                    //设置按钮是否展示
                    this.bottonView(this.afs.getPageParams(this).bottonView);
                    //传值到备案信息也看
                    this.channelId =this.afs.getPageParams(this).channelId;
                    this.channelStatus=this.afs.getPageParams(this).channelStatus;
                    this.channelStatusOldCar=this.afs.getPageParams(this).channelStatusOldCar;
                    this.getDetailAddress(this.afs.getPageParams(this).officeProvince,this.afs.getPageParams(this).officeAddress);
                    this.uploadReadOnly=false;
                    this.businessType= this.afs.getPageParams(this).businessType.split(',');
                }else if(this.afs.getPageParams(this).operationType==2){
                    //传入是否拥有新车账号权限
                    this.isNewCarRole=this.afs.getPageParams(this).isNewCarRole;
                    //传入是否有二手车账户权限
                    this.isOldCarRole=this.afs.getPageParams(this).isOldCarRole;
                    this.newCarRole=this.afs.getPageParams(this).isNewCarRole;
                    this.oldCarRole=this.afs.getPageParams(this).isOldCarRole;
                    //传入页面渠道类型判断渠道归属赋值
                    this.channelType=this.afs.getPageParams(this).channelType;
                    if(this.channelType=='01'){
                        // 说明是直营
                        this.operationUser='01';
                    }else{
                        // 说明我是非直营
                        this.operationUser='00';
                    }
                    //设置页面是否禁用
                    this.basicView(this.afs.getPageParams(this).infoView);
                    //获取渠道基本信息
                    this.channel(this.afs.getPageParams(this).channelId);
                    //设置按钮是否展示
                    this.bottonView(this.afs.getPageParams(this).bottonView);
                    //传值到备案信息也看
                    this.channelId =this.afs.getPageParams(this).channelId;
                    this.channelStatus=this.afs.getPageParams(this).channelStatus;
                    this.channelStatusOldCar=this.afs.getPageParams(this).channelStatusOldCar
                    this.uploadReadOnly=true;
                    this.businessType= this.afs.getPageParams(this).businessType.split(',');
                }
            },
            getDetailAddress(v,n){
                this.$refs.basicInfoModify.getDetailAddress(v,n);
            },
            channel(v){
                //渠道基本信息获取
                this.$refs.basicInfoModify.getChannelInfo(v);
                //收款账号信息获取
                this.$refs.accountModify.getAccountInfo(v);
                //新车授权区域
                this.$refs.basicInfoModify.getMainAreaListNew(v);
                //二手车授权区域
                this.$refs.basicInfoModify.getMainAreaListOld(v);
                //主营品牌
                this.$refs.basicInfoModify.getBaseTreeList(v);
                //新车授权车型
                this.$refs.basicInfoModify.checkAllNewCar(v);
                //二手车授权车型
                this.$refs.basicInfoModify.checkAllOldCar(v);
                //获取部门树
                this.$refs.useInfo.getDeptInfoTree(v);
                //备案信息获取
                this.$refs.recordInfo.getWitnessList(v);
                //档案日志信息获取
                this.$refs.archivesLog.getArchivesLogInfo(v);
                this.channelId =v;
            },
            basicInfoView(v){
                //新车或者二手车赋值
                this.$refs.basicInfoModify.addCarRole(this.newCarRole,this.oldCarRole);
                //授权区域初始化
                this.$refs.basicInfoModify.getMainAreaList();
                //主营品牌树初始化
                this.$refs.basicInfoModify.getBaseTreeList();
                //授权车型树初始化
                this.$refs.basicInfoModify.getCarsTreeList();
                //基础信息
                this.$refs.basicInfoModify.readOnlyInfo(v);
                //收款账号信息
                this.$refs.accountModify.readOnlyInfo(v);
            },
            basicView(v){
                //基础信息
                this.$refs.basicInfoModify.readOnlyInfo(v);
                //收款账号信息
                this.$refs.accountModify.readOnlyInfo(v);
                //备案信息
                this.$refs.recordInfo.readOnlyInfo(v);
            },
            toggle(index){
                this.curTab=index;
            },
            submit(){
                this.$refs.basicInfoModify.basicSubmit();
            },
            save(){
                if(this.curTab=="0"){
                    //基本信息
                    this.$refs.basicInfoModify.basicSave();
                }else if(this.curTab=="1"){
                    //收款账号信息
                    let channelId = this.channelId;
                    if(channelId==""||channelId == undefined) {
                        this.$Message.error("请先保存基本信息");
                        return;
                    }
                    this.$refs.accountModify.invoiceSave();
                }
            },
            blacklist(){
                //黑名单
                this.$refs.basicInfoModify.blackChannel();
            },
            back(){
                //关闭页面
                this.afs.closeTab(this);
            },
            setchannelId(v){
                //获取子组件基本信息页面保存的渠道id
                this.channelId=v;

            },
            //点击编辑查看按钮展示不通的按钮
            bottonView(flag){
                this.typeCode=flag;
            },
            initGetFilterParams() {
                let json ={
                    channelBelong:this.channelType,
                    businessTypeNewCar:this.isNewCarRole,
                    businessTypeOldCar:this.isOldCarRole
                }
                let businessType = this.businessType;
                if(businessType !=null && businessType.length>0){
                    if(businessType.length===1 && businessType[0]=="01"){
                        //新车附件
                        json.businessTypeNewCar="1";
                        //二手车二手车
                        json.businessTypeOldCar="0";
                    }else if(businessType.length===1 && businessType[0]=="02"){
                        json.businessTypeNewCar="0";
                        json.businessTypeOldCar="1";
                    }else if(businessType.length===2){
                        json.businessTypeNewCar="1";
                        json.businessTypeOldCar="1";
                    }else{
                        json.businessTypeNewCar="0";
                        json.businessTypeOldCar="0";
                    }
                };
                this.uploadParam.busiNo = this.channelId;
                this.uploadParam.belongNo = this.channelId;
                this.uploadParam.busiData = json;
                this.uploadParam.busiType = "dealerOnline";
                this.canUpload=true;
            },
            setBusinessType(val){
                //获取勾选的业务类型
                console.log("-------------",val)
                this.businessType=val;
                this.initGetFilterParams();
            },
        },
        mounted() {
            this.init();
            if(this.channelId){
                this.initGetFilterParams();
            }
        }
    }
</script>

<style scoped>
    .dealer .btns{
        background-color: white;
        padding: 20px 0 0 0;
    }
    .dealer .btns button{
        margin-right: 50px;
    }

    .dealer .channelClick{
        display: flex;
        flex-flow: row;
        justify-content: flex-end;
        align-items: center;
    }
    .dealer .ivu-spin-fix{
        background-color: hsla(0,0%,100%,.5)
    }

    .dealer .demo-spin-col{
        height: 100px;
        position: relative;
        border: 1px solid #eee;
    }
    .dealer .demo-spin-icon-load{
        animation: ani-demo-spin 1s linear infinite;
    }
</style>
